﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.DynamicData;
using System.Collections.Specialized;

namespace Catalyst.Web.DynamicData
{
    /// <summary>
    /// The base class used by UserControls that implements an equality comparisson. 
    /// </summary>
    public abstract class EqualsFilterUserControlBase : FilterTemplateUserControlBase
    {
        public abstract string Value { get; set; }
        public abstract TypeCode ValueType { get; }

        public override IEnumerable<Parameter> GetWhereParameters(IDynamicDataSource dataSource)
        {
            yield return new EqualsExpressionParameter() { Name = Column.Name, ValueType = ValueType, Value = Value };
        }

        public override void LoadQueryStringParameters(NameValueCollection parameters)
        {
            Value = parameters[Column.Name];
        }

        public override NameValueCollection SaveQueryStringParameters()
        {
            NameValueCollection parameters = new NameValueCollection();
            parameters.Add(Column.Name, Value);
            return parameters;
        }

        public override void Clear()
        {
            Value = string.Empty;
        }
    }
}
